package test;


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import java.util.Random;

import mapreduce.MapReduce;
import mapreduce.Mapper;
import mapreduce.Reducer;
import mapreduce.SimpleMapReduce;
import util.CommandLine;

/**
 * @author Li Jun Mulin
 * 
 */
public class RandomCounter {

	MapReduce<String, String> mr;

	public String getResult() {
		return (String) mr.getResult();
	}

	public void init() {
		FileReader reader;
		BufferedReader br;
		String str = null;
		try {
			reader = new FileReader(
					"C:\\Users\\mulin0424\\Desktop\\aaa.txt");
			br = new BufferedReader(reader);

			Reducer<String, Mapper<String>, String> r = new Reducer<String, Mapper<String>, String>() {
				public String doReducer(List<Mapper<String>> mappers) {
					return "b";
				}
			};
			mr = new SimpleMapReduce<String, String>(4, r);
			TestMapper<String> m;
			while ((str = br.readLine()) != null) {
				m = new TestMapper<String>(str);
				mr.addMapper(m);
			}


			br.close();
			reader.close();

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		RandomCounter rc = new RandomCounter();
		System.out.println("---- Stating...");
		long t1 = System.currentTimeMillis();
		rc.init();
		String r = rc.getResult();
		long t2 = System.currentTimeMillis();
		System.out.println("---- Result: " + r);
		System.out.println("Time:" + (t2 - t1));
		System.out.println(Runtime.getRuntime().availableProcessors());
		// StringBuffer sb= new StringBuffer("");
		// FileReader reader;
		// try {
		// reader = new
		// FileReader("C:\\Users\\mulin\\Desktop\\HelloWorldServlet.java");
		// BufferedReader br = new BufferedReader(reader);
		//	          
		// String str = null;
		//	          
		// while((str = br.readLine()) != null) {
		// sb.append(str+"\n");
		//	                
		// System.out.println(str);
		// }
		//	          
		// br.close();
		// reader.close();
		// } catch (FileNotFoundException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// } catch (IOException e2) {
		// // TODO Auto-generated catch block
		// e2.printStackTrace();
		// }

	}

}
